package org.jimmy.tang.designpattern.behavior.iterator;

/**
 * @author jimmy
 * 
 */
public class IteratorImpl implements Iterator {
    private List list;

    private int index;

    public IteratorImpl(List list) {
        index = 0;
        this.list = list;
    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.iterator.Iterator#next()
     */
    @Override
    public Object next() {
        Object obj = list.get(index);
        index++;
        return obj;

    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.iterator.Iterator#first()
     */
    @Override
    public void first() {
        index = 0;

    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.iterator.Iterator#last()
     */
    @Override
    public void last() {
        index = list.getSize();

    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.iterator.Iterator#hasNext()
     */
    @Override
    public boolean hasNext() {
        return index < list.getSize();

    }

}
